package homeadapter;

import android.content.Context;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.ListView;
import android.widget.TextView;

import com.bumptech.glide.Glide;
import com.yztc.thinkpad.mandemo.R;

import java.net.IDN;
import java.util.ArrayList;
import java.util.List;

import homebean.PingpaiBean;

/**
 * Created by Administrator on 2016/10/7.
 */
public class HomeListViewAdapter extends BaseAdapter {
    private Context context;
    private List<PingpaiBean.DataBean.SchoolBean> mlist;

    public HomeListViewAdapter(Context context, List<PingpaiBean.DataBean.SchoolBean> mlist) {
        this.context = context;
        this.mlist = mlist;
    }
    @Override
    public int getCount() {
        return mlist.size();
    }

    @Override
    public Object getItem(int i) {
        return mlist.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder mviewHolder;
        if (view==null){
            view= LayoutInflater.from(context).inflate(R.layout.home_list_item,null);
            mviewHolder=new ViewHolder();
            mviewHolder.iv_home_image= (ImageView) view.findViewById(R.id.iv_home_image);
            mviewHolder.tv_home_clickCount= (TextView) view.findViewById(R.id.tv_home_clickCount);
            mviewHolder.tv_home_title= (TextView) view.findViewById(R.id.tv_home_title);
            view.setTag(mviewHolder);
        }else{
            mviewHolder= (ViewHolder) view.getTag();
        }
        Glide.with(context).load(mlist.get(i).getImage()).placeholder(R.mipmap.default_banner).into(mviewHolder.iv_home_image);
        mviewHolder.tv_home_title.setText(mlist.get(i).getTitle());
        if (""+mlist.get(i).getClickCount()!=null){
            mviewHolder.tv_home_clickCount.setText(""+mlist.get(i).getClickCount());
        }
        return view;
    }
    static  class ViewHolder{
        TextView tv_home_title,tv_home_clickCount;
        ImageView iv_home_image;
    }
}
